Skip to content

Conversation

@samin-z
Copy link

@samin-z samin-z commented Jan 8, 2026

This PR is a fix for #1840 and #2237.

  • add new value called columnName to response when saving new row.
  • return clear error message when user add none-existing row id.

@samin-z samin-z requested review from blizzz and enjeck as code owners January 8, 2026 13:48
@samin-z samin-z marked this pull request as draft January 8, 2026 13:59
@samin-z samin-z marked this pull request as ready for review January 12, 2026 09:29
@blizzz blizzz added the 3. to review Waiting for reviews label Jan 12, 2026
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort @samin-z! I have left a few remarks, what do you think?

* @param 'tables'|'views' $nodeCollection Indicates whether to create a row on a table or view
* @param int $nodeId The identifier of the targeted table or view
* @param string|array<string, mixed> $data An array containing the column identifiers and their values
* @return DataResponse<Http::STATUS_OK, TablesRow, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added field should be reflected in the response definition of TablesRow, cf. https://github.com/nextcloud/tables/blob/main/lib/ResponseDefinitions.php#L76-L84

lib/Db/Row2.php Outdated
Comment on lines 162 to 164
/**
* return merged response-only metadata into the data cells.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method names says this already, no need to duplicate :)

What we want is however a @return annotation with the array shape. Or @psalm-return as done at jsonSerialize(), which itself would need to be adjusted afterwards.

Did you double check, cannot we only extend jsonSerialize() instead of adding a similar method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was a bit hesitant on using 'jsonSerialize' as i thought i might interfere in another place, but did more testing and it's fine.

lib/Db/Row2.php Outdated
private ?string $lastEditBy = null;
private ?string $lastEditAt = null;
private ?array $data = [];
private array $cellMeta = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should need to be added to a VIRTUAL_PROPERTIES const, otherwise the Mapper will complain. Have a look at https://github.com/nextcloud/tables/blob/main/lib/Db/Column.php#L161C2-L161C114 for comparison.

Also, the name is too broad and not specific (same problem with data already…), but right now I am also missing a better suggestion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill rename it cellMetadata as the array holds metadata for each cell.

$fullRowData = [];
$columnNames = [];

foreach ($columns as $c) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foreach ($columns as $c) {
foreach ($columns as $column) {

Please don't save bytes where it is not necessary :)


$rows = $data instanceof RowDataInput ? iterator_to_array($data) : $data;

foreach ($rows as $r) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

// attached columnname to returned row for the response only
foreach ($fullRowData as $meta) {
if (isset($meta['columnId']) && array_key_exists('columnName', $meta)) {
$insertedRow->addCellMeta((int)$meta['columnId'], ['columnName' => $meta['columnName']]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we generate it in Row2 instead? data is populated there. Having all logic in Row2 would capsulate it there and not leak logic to other classes around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants